package com.lzl.artisan.service.impl;

import com.lzl.artisan.model.AccountUser;
import com.lzl.artisan.model.User;
import com.lzl.artisan.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailServiceImpl implements UserDetailsService {
    @Autowired
    private UserService userService;


    @Override
    public UserDetails loadUserByUsername(String phone) throws UsernameNotFoundException {
        User user = userService.getByPhone(phone);
        if (user == null) {
            throw new UsernameNotFoundException("用户名或密码不正确!");
        }
        return new AccountUser(user.getId(), user.getPhone(), user.getPassword(), null);
    }
}
